﻿using System.Collections.Generic;
using System.IO;

public class TxtExportRecordService : IExportRecordService
{
    private StreamWriter _streamWriter;

    public void Start(string exportPath)
    {
        _streamWriter = File.CreateText(exportPath);
    }

    public void Export(int inputId, List<InputOp> inputOps)
    {
        _streamWriter.WriteLine("id:" + inputId);
        foreach (var inputOp in inputOps)
        {
            int bitOp = 0;
            if (inputOp.forward)
            {
                bitOp |= 0x01;
            }

            if (inputOp.left)
            {
                bitOp |= 0x02;
            }

            if (inputOp.back)
            {
                bitOp |= 0x04;
            }

            if (inputOp.right)
            {
                bitOp |= 0x08;
            }
            
            if (inputOp.buttonA)
            {
                bitOp |= 0x10;
            }
            
            if (inputOp.buttonB)
            {
                bitOp |= 0x20;
            }

            _streamWriter.WriteLine(bitOp);
        }
    }

    public void End()
    {
        _streamWriter.Flush();
        _streamWriter.Close();
    }
}